<?php 

class Silk_Pms_ExchangeController extends Mage_Core_Controller_Front_Action
{
    public function preDispatch()
    {
        parent::preDispatch();
        $session = Mage::getSingleton('customer/session');
        // if(!$session->isLoggedIn())
        // {
        //     $this->_redirect('customer/account/login');
        // }
        return $this;
    }
    public function viewAction(){
        $id = $this->getRequest()->getParam("exchange_id");
        $exchange = Mage::getModel('pms/exchange')->load($id);
        if(!$exchange || !$exchange->getId())
        {
            echo "活动不存在！";
            return;
        }
        $block = $this->getLayout()->createBlock("pms/exchange_jifen_jifen".$exchange->getTemplateId());
        
        echo $block->toHtml();

    }
    public function getexchangedqtyAction(){
        $result = array('error'=>true,'message'=>'');
        $id = $this->getRequest()->getParam("activity_id");
        $productId = $this->getRequest()->getParam("product_id");
        $exchangeproducts = Mage::getModel("pms/exchangeproduct")
                          ->getCollection()
                          ->addFieldToFilter("activity_id",$id)
                          ->addFieldToFilter("product_id",$productId);
        $item =  $exchangeproducts->getFirstItem();
        $exchangedqty = $item->getExchangedQty(); 
        $qty = $item->getQty();
        $result = array('error'=>true,'message'=>$exchangedqty,"qty"=>$qty);
        echo json_encode($result);
    }


}